<template>
  <div>
    <el-card class="cardBox">
      <div class="title">
        <h1 class="">大墩沟风共场地空气加热器</h1>
<!--        <el-button @click="alarmBtn">报警总数：0</el-button>-->
      </div>

      <!-- 参数表格 -->
      <div style="border: 1px solid var(--el-border-color-light)">
        <el-row class="header-row">
          <el-col :span="8"></el-col>
          <el-col :span="8" class="title-col">
            <span>大墩沟风共场地空气加热器</span>
          </el-col>
          <el-col :span="8" class="status-col">
            <div class="status-container">
              <div>
                <span>通讯故障</span>
                <i class="yuan yellow"></i>
              </div>
              <div>
                <span>无故障</span>
                <i class="yuan grey"></i>
              </div>
              <div>
                <span>运行</span>
                <i class="yuan green"></i>
              </div>
              <div>
                <span>报警</span>
                <i class="yuan red"></i>
              </div>
            </div>
          </el-col>
        </el-row>
        <el-row class="threeTitle" >
          <el-col :span="24">空气加热机组</el-col>
        </el-row>
        <el-row class="threeTitle">
          <el-col :span="6">项目</el-col>
          <el-col :span="3">1</el-col>
          <el-col :span="3">2</el-col>
          <el-col :span="3">3</el-col>
          <el-col :span="3">4</el-col>
          <el-col :span="3">5</el-col>
          <el-col :span="3">6</el-col>
        </el-row>
        <el-row >
          <el-col :span="6">状态</el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_22_N('RunFeed2_DI', operator.NO).value ? 'green' : 'grey'
              "
          ></div>
          </el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_22_N('RunFeed2_DI', operator.NO).value ? 'green' : 'grey'
              "
          ></div></el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_22_N('RunFeed2_DI', operator.NO).value ? 'green' : 'grey'
              "
          ></div></el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_22_N('RunFeed2_DI', operator.NO).value ? 'green' : 'grey'
              "
          ></div></el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_22_N('RunFeed2_DI', operator.NO).value ? 'green' : 'grey'
              "
          ></div></el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_22_N('RunFeed2_DI', operator.NO).value ? 'green' : 'grey'
              "
          ></div></el-col>
        </el-row>
        <el-row>
          <el-col :span="6">进风阀门开度（%）</el-col>
          <el-col :span="1">V1</el-col>
          <el-col :span="2">{{
            NamePD_22_N("OpCurr1_AI", operator.Divide, 10, 2)
          }}</el-col>
          <el-col :span="1">V2</el-col>
          <el-col :span="2">{{
            NamePD_22_N("OpCurr2_AI", operator.Divide, 10, 2)
          }}</el-col>
          <el-col :span="1">V3</el-col>
          <el-col :span="2">{{
            NamePD_22_N("OpCurr3_AI", operator.Divide, 10, 2)
          }}</el-col>
          <el-col :span="1">V4</el-col>
          <el-col :span="2">{{
            NamePD_22_N("OpCurr4_AI", operator.Divide, 10, 2)
          }}</el-col>
          <el-col :span="1">V5</el-col>
          <el-col :span="2">{{
            NamePD_22_N("OpCurr5_AI", operator.Divide, 10, 2)
          }}</el-col>
          <el-col :span="1">V6</el-col>
          <el-col :span="2">
            {{
              NamePD_22_N("OpCurr5_AI", operator.Divide, 10, 2)
            }}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">进风温度（℃）</el-col>
          <el-col :span="1">T11</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr1_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T12</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr2_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T13</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr3_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T14</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr4_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T15</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr5_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T16</el-col>
          <el-col :span="2">
            {{
              NamePD_22_N("OpCurr5_AI", operator.Divide, 10, 2)
            }}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">出风温度（℃）</el-col>
          <el-col :span="1">T21</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr1_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T22</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr2_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T23</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr3_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T24</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr4_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T25</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr5_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T26</el-col>
          <el-col :span="2">
            {{
              NamePD_22_N("OpCurr5_AI", operator.Divide, 10, 2)
            }}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">井口温度（℃）</el-col>
          <el-col :span="1">T13</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr1_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T23</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr2_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T33</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr3_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T43</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr4_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T53</el-col>
          <el-col :span="2">{{
              NamePD_22_N("OpCurr5_AI", operator.Divide, 10, 2)
            }}</el-col>
          <el-col :span="1">T63</el-col>
          <el-col :span="2">
            {{
              NamePD_22_N("OpCurr5_AI", operator.Divide, 10, 2)
            }}
          </el-col>
        </el-row>
        <el-row class="threeTitle" >
          <el-col :span="24">暖风机</el-col>
        </el-row>
        <el-row class="threeTitle">
          <el-col :span="6">项目</el-col>
          <el-col :span="3">1</el-col>
          <el-col :span="3">2</el-col>
          <el-col :span="3">3</el-col>
          <el-col :span="3">4</el-col>
          <el-col :span="3"></el-col>
          <el-col :span="3"></el-col>
        </el-row >
        <el-row >
          <el-col :span="6">状态</el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_22_N('RunFeed2_DI', operator.NO).value ? 'green' : 'grey'
              "
          ></div>
          </el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_22_N('RunFeed2_DI', operator.NO).value ? 'green' : 'grey'
              "
          ></div></el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_22_N('RunFeed2_DI', operator.NO).value ? 'green' : 'grey'
              "
          ></div></el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_22_N('RunFeed2_DI', operator.NO).value ? 'green' : 'grey'
              "
          ></div></el-col>
          <el-col :span="3"></el-col>
          <el-col :span="3"></el-col>
        </el-row>

      </div>
    </el-card>

    <!-- 公司log -->
    <el-row>
      <div class="kx-log-box">
        <img
          class="kx-img"
          src="@/assets/images/kxauto.png"
          alt="描述图片的文字"
        />
        <span>开轩自动化</span>

        <span class="kx-hezuo">
          商务合作：18509234888（同微信） 技术支持：18691805301（同微信）
        </span>
      </div>
    </el-row>

    <!-- 弹窗 -->
    <form-dialog ref="formRef" />
    <faultFormDialog ref="faultRef" />
    <switchFormDialog ref="switchRef" />
  </div>
</template>

<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import { ElMessage } from "element-plus";
import { act, createWebSocket } from "@/utils/websocket"; //引入websocket
import { operator } from "@/utils/op_enums";
import { NamePD_22_N, NamePD_22_N_GEN } from "@/utils/beltPositioningMethod.ts";

// 引入子组件
import formDialog from "./alarmForm.vue";
import faultFormDialog from "./faultForm.vue";
import switchFormDialog from "./switchForm.vue";
import { BPQMap } from "../../../utils/BPQMap";

const formRef = ref();
const faultRef = ref();
const switchRef = ref();
const HUANINGBH = [
  "HNLineLock1_DI",
  "HNLineLock2_DI",
  "HNLineLock3_DI",
  "HNLineLock4_DI",
  "HNLineLock5_DI",
  "HNLineLock6_DI",
  "HNLineLock7_DI",
  "HNLineLock8_DI",
  "HNLineLock9_DI",
  "HNLineLock10_DI",
  "HNLineLock11_DI",
  "HNLineLock12_DI",
  "HNLineLock13_DI",
  "HNLineLock14_DI",
  "HNLineLock15_DI",
  "HNLineLock16_DI",
  "HNLineLock17_DI",
  "HNLineLock18_DI",
  "HNLineLock19_DI",
  "HNLineLock20_DI",
  "HNLineLock21_DI",
  "HNLineLock22_DI",
  "HNLineLock23_DI",
  "HNLineLock24_DI",
  "HNLineLock25_DI",
  "HNLineLock26_DI",
  "HNLineLock27_DI",
  "HNLineLock28_DI",
  "HNLineLock29_DI",
  "HNLineLock30_DI",
  "HNLineLock31_DI",
  "HNLineLock32_DI",
  "HNLineLock33_DI",
  "HNLineLock34_DI",
  "HNLineLock35_DI",
  "HNLineLock36_DI",
  "HNLineLock37_DI",
  "HNLineLock38_DI",
  "HNLineLock39_DI",
  "HNLineLock40_DI",
  "HNLineLock41_DI",
  "HNLineLock42_DI",
  "HNLineLock43_DI",
  "HNLineLock44_DI",
  "HNLineLock45_DI",
  "HNLineLock46_DI",
  "HNLineLock47_DI",
  "HNLineLock48_DI",
  "HNLineLock49_DI",
  "HNLineLock50_DI",
  "HNLineLock51_DI",
  "HNLineLock52_DI",
  "HNLineLock53_DI",
  "HNLineLock54_DI",
];

onMounted(() => {
  createWebSocket("%PD_22_N%");
});
const alarmBtn = () => {
  formRef.value.openDialog();
};
const faultpopuBtn = () => {
  faultRef.value.openDialog();
};
const switchBtn = () => {
  switchRef.value.openDialog();
};
const faultResetBtn = () => {
  ElMessage.info("故障复位");
};
</script>

<style lang="scss" scoped>
.cardBox {
  background-color: var(--el-bg-color);
  border-radius: 8px;
  box-shadow: var(--el-box-shadow-light);
  border: 1px solid var(--el-border-color-light);

  /* 左上方标题 */
  .title {
    border-bottom: 1px solid var(--el-border-color);
    padding-bottom: 15px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    h1 {
      color: var(--el-text-color-primary);
      font-size: 20px;
      margin: 0;
      font-weight: 500;
    }

    .el-button {
      background-color: var(--el-color-danger);
      color: var(--el-color-white);
      border: none;
      border-radius: 4px;
      padding: 8px 15px;
      font-weight: 500;

      &:hover {
        background-color: var(--el-color-danger-light-3);
      }
    }
  }

  /* 表格标题 + 四个指示灯 */
  .header-row {
    display: flex;
    align-items: center;
    background-color: var(--el-fill-color-lighter);
    font-weight: 500;
    color: var(--el-text-color-primary);
    padding: 10px;
    .el-col {
      height: 40px;
      display: flex;
      align-items: center;
      border: 1px solid transparent;
    }

    .title-col {
      justify-content: center;

      span {
        font-size: 18px;
      }
    }

    .status-col {
      justify-content: end;
      .status-container {
        display: flex;
        gap: 14px;

        div {
          background: var(--el-fill-color-blank);
          border: 1px solid var(--el-border-color-lighter);
          border-radius: 4px;
          padding: 4px 8px;
          display: flex;
          align-items: center;
          gap: 6px;
          font-size: 13px;

          span {
            padding: 0 4px;
          }

          .yuan {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            flex-shrink: 0;
            @extend %status-colors;
          }
        }
      }
    }
  }

  /* 表格的标题 项目 + 状态值 */
  .threeTitle {
    .el-col {
      background-color: var(--el-fill-color) !important;
    }
  }

  /* 每一小格子的边框 背景色 */
  .el-col {
    border: 1px solid var(--el-border-color-lighter);
    text-align: center;
    padding: 6px 5px;
    font-size: 13px;
    color: var(--el-text-color-regular);

    &:first-child,
    &:nth-child(7),
    &:nth-child(13),
    &:nth-child(15) {
      font-weight: 500;
      color: var(--el-text-color-primary);
      background-color: var(--el-fill-color-lighter);
    }
  }

  /* 子页面设备参数--指示灯 */
  .indicator-light {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--el-border-color);
    margin: 0 auto;
    @extend %status-colors;
  }

  /* 华宁沿线闭锁 */
  .huaning-title {
    display: flex;
    align-items: center;
    justify-content: center;
    // height: 100%;
    color: var(--el-text-color-primary);
    font-weight: 500;
  }

  .hn-container {
    display: flex;
    flex-wrap: wrap;
    gap: 50px;
    padding: 8px;
    align-items: center;
    background-color: var(--el-fill-color-lighter);
    border-radius: 4px;

    span {
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .hn-span {
      display: inline-flex;
      align-items: center;
    }
  }

  .index-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
    justify-content: flex-start;
    background-color: var(--el-fill-color-lighter);
    border-radius: 4px;
    min-height: 40px;
    align-items: center;
  }

  .index-circle {
    width: 26px;
    height: 26px;
    background-color: var(--el-border-color);
    border-radius: 50%;
    color: var(--el-text-color-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    font-weight: 500;
    @extend %status-colors;
  }

  .terminal-voltage {
    color: var(--el-color-warning);
    margin-left: 20px;
    font-size: 13px;
  }

  // 定义基础颜色类（只定义一次）
  %status-colors {
    &.green {
      background-color: var(--el-color-success);
    }
    &.red {
      background-color: var(--el-color-danger);
    }
    &.yellow {
      background-color: var(--el-color-warning);
    }
    &.grey {
      background-color: var(--el-border-color-dark); // 比默认边框色更深的灰色
    }
  }
}
</style>
